package com.example.administrator.mvpnetproject.login;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.mvpnetproject.R;
import com.example.lib_base.base.mvp.view.BaseMvpActivity;

/**
 * @author yedong
 * @date 2019/1/11
 */
public class TestLoginActivity extends BaseMvpActivity<ILoginView, LoginPresenter> implements ILoginView {

    private EditText et_user;
    private EditText et_password;
    private TextView tv_login;

    public static void start(Context context) {
        Intent intent = new Intent(context, TestLoginActivity.class);
        Bundle bundle = new Bundle();
        intent.putExtras(bundle);
        context.startActivity(intent);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_login;
    }

    @Override
    protected LoginPresenter createPresenter() {
        return mPresenter = new LoginPresenter(this);
    }

    @Override
    protected void initView() {
        et_user = $(R.id.et_user);
        et_password = $(R.id.et_password);
        tv_login = $(R.id.tv_login);
    }

    @Override
    protected void loadData() {
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        tv_login.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mPresenter.login(et_user.getText().toString().trim(), et_password.getText().toString().trim());
            }
        });
    }

    @Override
    public void onLoginSuccess(LoginModel model) {
        Toast.makeText(this,model.getName(),Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onLoginFail() {

    }


}
